package router

import (
	controller "image-server/controllers"
	"image-server/middleware"

	"github.com/gin-gonic/gin"
)

// InitRouter 初始化Gin路由配置
func InitRouter() *gin.Engine {
	// 创建Gin引擎实例
	r := gin.Default()

	userCtrl := &controller.UserController{}
	albumCtrl := &controller.AlbumController{}
	imageCtrl := &controller.ImageController{}
	shareCtrl := &controller.ShareController{}
	// 用户相关路由
	r.GET("/", userCtrl.Index) // 首页路由

	// -------------------------- 认证路由分组 --------------------------
	auth := r.Group("")
	auth.Use(middleware.Auth())
	{
		//auth.GET("/albums", userCtrl.HandleLoginCallback) // 登录回调处理
		// 相册相关接口
		auth.GET("/albums/list", albumCtrl.GetUserAlbums)
		auth.POST("/albums/create", albumCtrl.CreateAlbum)
		auth.GET("/albums/detail/:id", albumCtrl.GetAlbumDetail)
		auth.PUT("/albums/:id", albumCtrl.UpdateAlbum)
		auth.DELETE("/albums/:id", albumCtrl.DeleteAlbum)
		// 查询指定用户的公开相册列表
		auth.GET("/albums/public/:user_id", albumCtrl.GetUserPublicAlbums)

		// 图片相关接口
		auth.POST("/images", imageCtrl.UploadImage)
		auth.GET("/albums/images/:albumId", imageCtrl.GetAlbumImages)
		auth.DELETE("/images/:id", imageCtrl.DeleteImage)
		auth.GET("/images/:id", imageCtrl.GetImageDetail)
		auth.PUT("/images/:id", imageCtrl.UpdateImage)

		//显示图片-显示缩略图或者原图
		auth.GET("/images/:id/display", imageCtrl.DisplayImage)

		// 分享相关接口
		// 分享图片
		auth.GET("/images/:id/share", imageCtrl.DownloadImage)
		//获取用户所有分享记录
		auth.GET("/share/:id", shareCtrl.GetUserShares)

		// STS相关接口
		auth.GET("/sts/getuploadtst", shareCtrl.GetUploadSTS) // 获取上传用的STS凭证
	}
	return r
}
